In This Part
by Kenn Scribner
In This Chapter
Until the introduction of dynamic HTML, Web pages were static ones presented to the browser. HTML (Hypertext Markup Language) was introduced to describe the visual formatting of information sent to Web browsers. After the page was published on the Web, the HTML-formatted information was simply to be viewed. If anything was to be changed, a request would be issued to and response received from the Web server, resulting in new HTML information being shipped to the client system.
When Microsoft designed Internet Explorer (IE) 4, though, they changed the rules of the game. Along with the usual Web browser functionality, Microsoft designed an HTML object model it called Dynamic HTML (DHTML). The whole idea behind DHTML was to allow scripted elements embedded within the HTML document to access and modify the contents of the Web page without interaction with the Web server. This makes for more snappy Web page performance, especially when the users Internet connection is over a modem.
It wasnt long after DHTMLs introduction that programmers realized DHTML was easily accessible from Visual Basic. The core of the Internet Explorer Web browser is an ActiveX control, and because ActiveX controls were originally designed to replace the Visual Basic Extension (VBX) corols, the IE ActiveX control (Ill call it MSIE for short) was and is a natural fit within Visual Basic.
I say just another ActiveX control, but this particular control packs a wallop. The Internet Explorer Web browser you see when you run IE 4 is a thin application built around this ActiveX control. MSIE handles the entire Web browsing task for the application, which includes visual formatting and rendering, HTML parsing, and even such arcane tasks as the users favorites storage and retrieval. It manages its own window, handles server downloads asynchronously (and is multithreaded), and deals with several protocols such as the popular File Transfer Protocol(FTP) and Hypertext Transport Protocol (HTTP).
In addition to the browsing aspects, it provides you with DHTML. What this really means is that you are now able to access the browsers HTML document, parse through the HTML, and do with the results as your application requires. The truly exciting part is that you arent limited to read-only HTML accessyou can also modify the HTML contents on-the-fly.
Tip:The sample programs in this chapter dont do DHTML justice from an artistic standpoint (that subject is a book in itself). They will show you how to access DHTML from Visual C++. I highly recommend that you visit the Microsoft Web site to see some of the amazing things you can do with DHTML. Many of Microsofts pages use DHTML to enhance the pages impact or present information in a new and different way.
In this chapter youll see some of the exciting things you can do with DHTML using MFC. But before I get into the details of DHTML, I need to explain how you use the MSIE ActiveX control, both in a document/view scenario and from a dialog box. After you have MSIE working in your application, you can invoke its DHTML COM interfaces.
When using MSIE with Visual C++ 6, you have two primary alternatives. First, if youre interested in using the standard MFC document/view architecture, you can use the new CHtmlView class in place of CView, or some other view class. And second, you can insert MSIE into a dialog box just as you would any other ActiveX control. Both methods are very easy to implement at least as far as activating the browser control is concerned. Ill begin with an overview of the basic capabilities of the control and then discuss its use in your applications.
The total functionality MSIE exposes comes from many files, but the primary file is named shdocvw.dll. This file is MSIE for all intents and purposes. The other files have more to do with Internet communication than the actual browsing process (see Chapter 25, WinInet Programming). In this section, Ill address the browsing aspect of MSIE. Ill defer the DHTML aspect until later in the chapter.
MSIE is an ActiveX control, and as such it also exposes several COM interfaces. The Web browser COM interface itself is called IWebBrowser2. Probably the easiest way to grasp what this interface provides you is to examine Listing 23.1, which is the code Developer Studio generates for you when you insert MSIE into your application. The length of Listing 23. 1 alone gives you some idea as to the power this control wields!
Note:The function names and parameters you see in Listing 23.1 are valid only when MSIE is inserted into your application by Developer Studio. As with all ActiveX controls you insert, Developer Studio queries the ActiveX control for the methods and properties it exposes and creates a C++ wrapper for you. This is what you see in Listing 23.1. The effect of this is that the method signatures differ if you call IWebBrowser2 directly. There is a direct correlation, though, so reading about IWebBrowser2 in the online help should help you understand the use of functions in Listing 23.1 that arent readily apparent to you at first glance.